<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>用户登录</title>
		<link rel="stylesheet" type="text/css" href="css/hui.css" />
		<link rel="stylesheet" type="text/css" href="css/my.css" />
		<link rel="stylesheet" type="text/css" href="css/animate.min.css" />
		<style>
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
			.link-area a {
				color: #0076FF;
				font-size: 16px;
			}
			
			.hui-login {
				background: #4CD964;
				color: #FFFFFF;
			}
			
			.hui-center-title {}
			
			.hui-center-title h1 {
				width: 80%;
				font-family: hoverTreeFont;
				color: green;
				border-bottom: none
			}
			
			.body-back{
				height: 100vh;width: 100vw;
				background-image: url(img/bg_new.png);
				background-repeat: no-repeat;
				background-size: 100vw 100vh;
				position: absolute;
			}	
			
		</style>

	</head>

	<body class="body-back">
		
			
		
		<div style="position: absolute;top:0%;width: 100%;">
			 <div style="margin-top:20%;width: 100%;position: relative;">
				<img src="img/icon_white.png" style="width: 40%;z-index: 2;position: relative;left: 50%;margin-left: -20%;" />
			</div> 
			
			<form style="flex: 1;" class="animated fadeIn" action="" id="form1" method="post" enctype="application/x-www-form-urlencoded">
				<div style="margin:28px; margin-top:0vh; background: rgba(0,0,0,0) !important;" class="hui-form">

					<div class="hui-form-items" style="display: flex; padding: 0; background: #fff;">
						<div style="flex-grow:1; height: 52px; width: 5%;">
							<img src="img/user.png" alt="" style="height: 50%; width: auto; margin: 11px 0 0 11px;" />
						</div>
						<input id="username" name="username" type="text" class="hui-input" checkType="string" placeholder="用户名" checkData="1,50"
						 checkMsg="用户名不能为空" style="width: 75% !important;flex-grow:1; margin: 15px 0;" />
					</div>
					<div class="hui-form-items" style="display: flex; padding: 0; background: #fff; margin-top: 17px;">
						<div style="flex-grow:1; height: 52px; width: 5%;">
							<img src="img/password.png" alt="" style="height: 50%; width: auto; margin: 11px 0 0 11px;" />
						</div>
						<input id="pwdw" type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checkType="string" id="pwd"
						 checkData="6,50" checkMsg="请输入不少于6位的密码" style="width: 75% !important;flex-grow:1; margin: 15px 0;" />
						<!--<input id="pwd" name="pwd" type="password" style="display: none;" />-->
					</div>

				</div>

				<div style="margin:28px 28px 0px 28px;">
					<button id="login" type="button" class="hui-button hui-button-large hui-login animated bounceInUp" style="z-index: 999;">登录</button>
					</br>
					<!--<button id="register" type="button" style="background: #FFFFFF;" class="hui-button hui-button-large">我要注册</button>-->
				</div>
			</form>

			
		</div>
		
		 <!--<div id="copyright" style="height: 50px; width: 100%; position: absolute; bottom: 10px;">
				<p style=" font-size: 12px; text-align: center; color: #fff;"> 版权所有 © 2020 All Copy Right 湖南元想科技有限公司</p>
				<p style=" font-size: 12px; text-align: center; color: #fff;">sensor@sureserve.cn</p>
			</div> -->

		<script type="text/javascript" src="js/func/hui.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/func/hui-form.js" charset="utf-8"></script>

		<script type="text/javascript" src="./js/MapJs/jq.js"></script>
		<script type="text/javascript" src="js/obj/my.js?version=201805300900" charset="UTF-8"></script>

		<script>
			hui.ready(function() {
				refresh();
				
				 $('body').css({'height':$(window).height()})
			});

			function refresh() {
				var name = localStorage.getItem("loginName") || "";
				hui("#username").val(name);
				var loginId = localStorage.getItem("loginId") || "";
				printLog(loginId, "登录姓名");
				if (loginId.length > 0) {
					if (localStorage.getItem("mapopenstate") == 'true') {
						hui.open("China_Map.html?loginId=" + loginId, {}, true, {});
					} else {
						hui.open("main_New.html?cityName=", {}, true, {});
					}
				}
			}

			hui.formInit();

			hui("#login").click(function() {
				//hui.open("main.html",{},true,{});	
				var name = hui("#username").val() || "";
				var pwd = hui("#pwdw").val() || "";

				if (name.length == 0) {
					hui.toast("请输入用户姓名!");
					return;
				}
				if (pwd.length == 0) {
					hui.toast("请输入密码!");
					return;
				}

				login(name, pwd);
			})

			/*	逻辑
			 
			 * 	登录后根据账号ID调用数据请求
			 * 	遍历所有数据的省份ID后去重
			 * 	
			 * 	只有新疆基地 || 新疆 湖南并存 打开中国地图
			 * 	只有湖南基地 打开湖南地图
			 * 	
			 * 	
			 * 
			 * */

			function login(name, pwd) {

				//var url = baseURL() + "/users_handler.ashx?action=user_login";
				var url = newBaseUrl() + "/user/login?username=" + encodeURI(encodeURIComponent(name)) + "&pwd=" + pwd;
				var param = {
					username: encodeURI(name),
					pwd: pwd
				};

				console.log(url);
				console.log(param);

				hui.loading("正在登录...");
				postJson(url, param, function(ret) {
					console.log(ret);

					localStorage.setItem("loginName", ret.result.user_name);
					localStorage.setItem("loginId", ret.result.id);
					localStorage.setItem("loginInfo", JSON.stringify(ret.result));
					localStorage.setItem("mapopenstate", ret.result.mapopenstate);

					hui("#pwdw").val("");
					hui.close("account.html");
					if (ret.result.mapopenstate) {
						hui.open("China_Map.html?loginId=" + ret.result.id, {}, true, {});
					} else {
						hui.open("main_New.html?cityName=", {}, true, {});
					}
				});
			}
			var winHeight = $(window).height(); //获取当前页面高度
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					//当软键盘弹出，在这里面操作
					//					alert('键盘弹出');
					$('#copyright').hide();
				} else {
					//当软键盘收起，在此处操作
					//					alert('键盘收起');
					$('#copyright').show();
				}
			});


			var huibackNum = 0;
			hui.Back = function() {
				//var selfW = plus.webview.currentWebview();
				//if(selfW.id == plus.runtime.appid || selfW.id == 'HBuilder') {
				if (huibackNum < 1) {
					hui.toast('再按一次退出程序');
					//hui.iconToast('操作成功', 'success');
					huibackNum++;
					setTimeout(function() {
						huibackNum = 0;
					}, 3000);
				} else {
					plus.runtime.quit();
				}
				//}
			}
		</script>

	</body>

</html>
